<template>
  <el-container class="app-wrapper">
    <el-aside width="200px" class="sidebar-container">
      <el-menu
        :default-active="activeMenu"
        class="el-menu-vertical"
        :router="true"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
      >
        <el-menu-item index="/">
          <el-icon><DataLine /></el-icon>
          <span>仪表盘</span>
        </el-menu-item>
        <el-menu-item index="/user-stats">
          <el-icon><User /></el-icon>
          <span>用户统计</span>
        </el-menu-item>
        <el-menu-item index="/simulation-stats">
          <el-icon><TrendCharts /></el-icon>
          <span>模拟统计</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    
    <el-container>
      <el-header height="60px" class="header">
        <div class="header-right">
          <el-dropdown @command="handleCommand">
            <span class="el-dropdown-link">
              {{ username }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
            </span>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item command="logout">退出登录</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter, useRoute } from 'vue-router'
import { DataLine, User, TrendCharts, ArrowDown } from '@element-plus/icons-vue'

export default defineComponent({
  name: 'App',
  components: {
    DataLine,
    User,
    TrendCharts,
    ArrowDown
  },
  setup() {
    const store = useStore()
    const router = useRouter()
    const route = useRoute()

    const username = computed(() => store.state.user.username)
    const activeMenu = computed(() => route.path)

    const handleCommand = (command: string) => {
      if (command === 'logout') {
        store.dispatch('user/logout')
        router.push('/login')
      }
    }

    return {
      username,
      activeMenu,
      handleCommand
    }
  }
})
</script>

<style lang="scss">
.app-wrapper {
  height: 100vh;
  
  .sidebar-container {
    background-color: #304156;
    
    .el-menu {
      border-right: none;
    }
  }
  
  .header {
    background-color: #fff;
    border-bottom: 1px solid #e6e6e6;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0 20px;
    
    .header-right {
      .el-dropdown-link {
        cursor: pointer;
        color: #409EFF;
      }
    }
  }
  
  .el-main {
    background-color: #f0f2f5;
    padding: 20px;
  }
}
</style> 